package com.bwie.system.controller;

import com.alibaba.fastjson.JSON;
import com.bwie.common.domain.User;
import com.bwie.common.result.Result;
import com.bwie.system.service.UserService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/User")
@Log4j2
public class UserController {
    @Autowired
    UserService userService;

    @Autowired
    HttpServletRequest request;

    /**
     * 校验账号
     * @param userName
     * @return
     */
    @PostMapping("/findByName/{userName}")
    public Result<User> findByName(@PathVariable String userName){
        log.info("功能名称，校验账号，请求URI：{}，请求方式：{}，请求参数：{}",
                request.getRequestURI(),request.getMethod(),userName);

        Result<User> result=userService.findByName(userName);

        log.info("功能名称，校验账号，请求URI：{}，请求方式：{}，响应结果：{}",
                request.getRequestURI(),request.getMethod(), JSON.toJSONString(result));
        return result;
    }
}
